const axios = require('axios');

async function testStudentAPI() {
    try {
        console.log('正在测试学生信息API...');
        
        // 先获取登录token
        console.log('1. 获取登录token...');
        const loginResponse = await axios.post('http://localhost/dev-api/login', {
            username: 'admin',
            password: 'admin123'
        });
        
        console.log('登录成功！token:', loginResponse.data.token);
        
        // 使用token调用学生信息API
        console.log('2. 调用学生信息列表API...');
        const studentResponse = await axios.get('http://localhost/dev-api/system/student/list', {
            headers: {
                'Authorization': 'Bearer ' + loginResponse.data.token
            }
        });
        
        console.log('学生信息API调用成功！');
        console.log('状态码:', studentResponse.status);
        console.log('返回数据:', JSON.stringify(studentResponse.data, null, 2));
        
        if (studentResponse.data.code === 200) {
            console.log('\n✅ 学生信息列表:');
            studentResponse.data.rows.forEach(student => {
                console.log(`- ID: ${student.studentId}, 姓名: ${student.studentName}, 性别: ${student.gender}, 介绍: ${student.introduction}`);
            });
        } else {
            console.log('❌ API返回错误:', studentResponse.data.msg);
        }
        
    } catch (error) {
        console.error('测试失败:', error.message);
        if (error.response) {
            console.error('响应数据:', error.response.data);
        }
    }
}

testStudentAPI();